mod pinyin_to_wade;
mod pinyin_dict_notone;

use  pinyin_to_wade::{PinyinType, get_pinyin_wade};
use  pinyin_dict_notone::{get_pinyin, get_word_pinyin};

pub fn converter(input: &str) -> String {
    let ret = input
        .split("")
        .filter(|x| !x.is_empty())
        .map(|x| get_pinyin(x))
        .collect::<Vec<_>>();

    let total = ret.iter().fold(1, |acc, x| acc * x.len());
    if total == 0 {
        return "".to_owned();
    }
    let mut all_pinyin = vec![vec![];total];
    for i in ret {
        let n = all_pinyin.len()/i.len();
        for j in 0..n {
            for k in i.iter().enumerate(){
                all_pinyin[j*(n-1)+k.0].push(k.1.0.clone());
            }
        }
    }
    let ret = all_pinyin
        .iter()
        .map(|x| x.join(" "))
        .filter(|x| x==&get_word_pinyin(input))
        .collect::<String>()
        .split(" ")
        .map(|x| get_pinyin_wade(&x, PinyinType::Pinyin))
        .collect::<Vec<_>>()
        .join(" ");
    if ret.is_empty(){
        ret
    }else{
        ret[0..1].to_uppercase() + &ret[1..]
    }
}
